<?php
/**
 *
 * This file contains {@link Domain51_Util_String_Hex}
 *
 *
 * @package Domain51
 *
 * @subpackage Domain51_Util
 *
 * @author Travis Swicegood <development [at] domain51 [dot] com>
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 *
 */

/**
 * Required class
 */
require_once 'Domain51/Util/String.php';

/**
 *
 * This class provides utility functions relating to hex strings
 *
 *
 * @package Domain51
 *
 * @subpackage Domain51_Util
 *
 * @author Travis Swicegood <development [at] domain51 [dot] com>
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 *
 */
class Domain51_Util_String_Hex
{
    /**
     *
     * Converts a hex string to decimal
     *
     *
     * @param string $string
     *
     * @return string
     *
     */
    public function toDecimal($string) {
        return hexdec($string);
    }
    
    
    /**
     *
     * Converts a hex string to base64
     *
     *
     * @param string $hex
     *
     * @return string
     */
    public function toBase64($hex) { 
        $string = new Domain51_Util_String();
        $raw = '';
        for($i = 0; $i < strlen($hex); $i += 2) {
            $raw .= $string->charFromInt($this->toDecimal(substr($hex, $i, 2)));
        }
        return base64_encode($raw);
    }
}

?>